///轨迹部分
var guijixinxiDlg;
var guijiLayer;
var guijiResultArray = [];
var guijiFeatureArray = [];

function guijixinxiCallback(res){
	if(guijixinxiDlg){
		alert("请先关闭已有对话框");
		return;
	}
	closeGuijixinxiDlgLogicFunc();
	res = eval(res);
	debugger;
	////为什么没有轨迹的结果res为undefined的？不能一个空？
	if(res==null){
		alert("暂无轨迹数据");
		return;
	}
	guijiResultArray =res;
	guijiFeatureArray =new Array(res.length);
	guijiLayer = new OpenLayers.Layer.Vector("guijiLayer"); 
	map.addLayer(guijiLayer);
	var resultStr = '<div style="width:250px;height:150px;font-size:11px;font-family:微软雅黑;overflow-y:auto;overflow-x:hidden;">'+
		'<table style="font-size:11px;width:240px;border-collapse: collapse;"><tr><td class="queryTd">显示</td><td class="queryTd">序号</td><td class="queryTd">时间</td></tr>';
	for(var i = 0;i<res.length;i++){
	    var timeStr = (res[i].time.year+1900)+"年"+(res[i].time.month+1)+"月"+(res[i].time.date)+"日"+(res[i].time.hours)+"时"+(res[i].time.minutes)+"分"+(res[i].time.seconds)+"秒";
		var str  ='<tr>'+
		'<td class="queryTd"><input type="checkbox" class="guijiCheck" id="'+i+'"/></td><td class="queryTd">'+(i+1)+'</td><td class="queryTd">'+timeStr+'</td>'+
		'</tr>';
		resultStr = resultStr + str;
	}
	resultStr = resultStr +"</table></div>";
	guijixinxiDlg = $.dialog({
		title: '灾害点轨迹',
		content: resultStr,
		dlgDivId: "guijixinxiDlgId",
		resize: false,
		max: false,
		left:"450px",
		top:'100px',
		width:'250px',
		height:'150px',
		min:guijixinxiDlgMinFunc,
		init:function(){
			//对按钮的监听
			$(".guijiCheck").click(guijiClick);
		},
		close:guijixinxiDlgCloseFunc
	});
}



function guijiClick(evt){
	var id = Number(evt.currentTarget.id);
	if(evt.currentTarget.checked){
		var obj = guijiResultArray[id];
		var lonlatstr = obj.lonlatstr;
		var lonlatArray = lonlatstr.split(";");
		var feature = createGPSLine(lonlatArray);
		guijiFeatureArray[id] = feature;
		guijiLayer.addFeatures(feature);
		var x = Number(lonlatArray[0].split(",")[0]);
		var y = Number(lonlatArray[0].split(",")[1]);
		////这个坐标没有转换
		//var lonlat = new OpenLayers.LonLat(x,y);
		var lonlat =  lonLat2Mercator(Number(x),Number(y))
		map.setCenter(lonlat);
	}else{
		guijiLayer.removeFeatures(guijiFeatureArray[id]);
	}
}

function createGPSLine(gpsLonLatArr){
	var lonlatPointsArray = [];
	for(var i =0;i<gpsLonLatArr.length;i++){
		
		var x = gpsLonLatArr[i].split(",")[0];
		var y = gpsLonLatArr[i].split(",")[1];
		var mocatorPoint = lonLat2Mercator(Number(x),Number(y));
		var point = new OpenLayers.Geometry.Point(mocatorPoint.x,mocatorPoint.y);
		lonlatPointsArray.push(point);
	}
	var line = new OpenLayers.Geometry.LineString(lonlatPointsArray);
	var style = new OpenLayers.Util.extend({ fill: true, stroke: true }, {
		fillColor: "#F06F69",
	    fillOpacity: 0.9, 
	    hoverFillColor: "white",
	    hoverFillOpacity: 0.9,
	    strokeColor: "#ee9900",
	    strokeOpacity: 1,
	    strokeWidth: 4,
	    strokeLinecap: "round",
	    strokeDashstyle: "solid",
	    hoverStrokeColor: "red",
	    hoverStrokeOpacity: 1,
	    hoverStrokeWidth: 0.2,
	    pointRadius: 6,
	    hoverPointRadius: 1,
	    hoverPointUnit: "%",
	    pointerEvents: "visiblePainted",
	    cursor: "inherit"
	});
	var feature =new OpenLayers.Feature.Vector(line,null,style);
	return feature;
}

function guijixinxiDlgMinFunc(){
	minDlgByAnimate(guijixinxiDlg);
}

function guijixinxiDlgCloseFunc(){
	closeGuijixinxiDlgLogicFunc();
	guijixinxiDlg = null;
}

function closeGuijixinxiDlgLogicFunc(){
	if(guijiLayer){
		map.removeLayer(guijiLayer);
		guijiLayer = undefined;
	}
	guijiFeatureArray = [];
	guijiResultArray = [];
}

/////////////定位部分/////////////////////////
var dingweiDlg;
var dingweiResArray = [];
var dingweiMarkArray = [];
var dingweiMarkLayer;

function dingweixinxiCallback(res){
	if(dingweiDlg){
		alert("请先关闭已有对话框");
		return;
	}
	closeDingweiDlgLogicFunc();
	res = eval(res);
	////为什么没有轨迹的结果res为undefined的？不能一个空？
	if(res==null){
		alert("暂无轨迹数据");
		return;
	}
	dingweiResArray = res;
	dingweiMarkArray = new Array(res.length);
	dingweiMarkLayer = new OpenLayers.Layer.Markers("dingweiMarkLayer");
	map.addLayer(dingweiMarkLayer);
	var resultStr =  '<div style="width:250px;height:150px;font-size:11px;font-family:微软雅黑;overflow-y:auto;overflow-x:hidden;">'+
			'<table style="font-size:11px;width:240px;border-collapse: collapse;"><tr><td class="queryTd">显示</td><td class="queryTd">序号</td><td class="queryTd">时间</td></tr>';
	for(var i = 0;i<res.length;i++){
	    var timeStr = (res[i].dwsj.year+1900)+"年"+(res[i].dwsj.month+1)+"月"+(res[i].dwsj.date)+"日"+(res[i].dwsj.hours)+"时"+(res[i].dwsj.minutes)+"分"+(res[i].dwsj.seconds)+"秒";
		var str  ='<tr>'+
		'<td class="queryTd"><input type="checkbox" class="dingweiCheck" id="'+i+'"/></td><td class="queryTd">'+(i+1)+'</td><td class="queryTd">'+timeStr+'</td>'+
		'</tr>';
		resultStr = resultStr + str;
	}
	resultStr = resultStr +"</table></div>";
	dingweiDlg = $.dialog({
		title: '灾害点定位',
		content: resultStr,
		dlgDivId: "dingweiDlgId",
		resize: false,
		max: false,
		left:"450px",
		top:'100px',
		width:'250px',
		height:'150px',
		min:dingweiDlgMinFunc,
		init:function(){
			//对按钮的监听
			$(".dingweiCheck").click(dingweiClick);
		},
		close:dingweiDlgCloseFunc
	});
	
}

function dingweiClick(evt){
	var id = Number(evt.currentTarget.id);
	if(evt.currentTarget.checked){
		var obj = dingweiResArray[id];
		var size = new OpenLayers.Size(16, 16);
		var icon = new OpenLayers.Icon('image/car.png', size);
		var point = lonLat2Mercator(Number(obj.jd),Number(obj.wd));
		var mark = new OpenLayers.Marker(new OpenLayers.LonLat(point.x,point.y),icon);
		dingweiMarkLayer.addMarker(mark);
		dingweiMarkArray[id] = mark;
		map.setCenter(mark.lonlat);
	}else{
		dingweiMarkLayer.removeMarker(dingweiMarkArray[id]);
	}
}

function dingweiDlgMinFunc(){
	minDlgByAnimate(dingweiDlg);
}

function dingweiDlgCloseFunc(){
	closeDingweiDlgLogicFunc();
	dingweiDlg = null;
}

function closeDingweiDlgLogicFunc(){
	if(dingweiMarkLayer){
		map.removeLayer(dingweiMarkLayer);
		dingweiMarkLayer = undefined;
	}
	dingweiMarkArray = [];
	dingweiResArray = [];
}

